<div class="row-fluid">
    <div class="box span12">
        <div class="box-header">
            <h2><i class="icon-pencil"></i>Notes</h2>
            <div class="box-icon">
                <a href="#" class="btn-minimize"><i class="icon-chevron-up"></i></a>
            </div>
        </div>
        <div class="box-content notes-list">
            <ul class="dashboard-list">
                <?php if ($notes != NULL): ?>
                    <?php foreach ($notes as $item): ?>
                        <li>
                            <div class="row-fluid">
                                <div class="span2">
                                    <?php
                                    $author_link = user()->id == $item->author ? '#' :
                                            ($this->isStaff ? '#' : $item->author_info->editUrl)
                                    ?>
                                    <a href="<?php echo $author_link ?>" title="<?php echo $item->author_info->name ?>">
                                        <img class="avatar" src="<?php echo $item->author_info->getAvartBySize(50, 50) ?>">
                                    </a>
                                </div>
                                <div class="span10">
                                    <a href="<?php echo $author_link ?>">
                                        <i><strong><?php echo $item->author_info->name ?></strong> noted:</i>
                                    </a>
                                    "<?php echo $item->note_content ?>"
                                    <br>
                                    <i>at <?php echo $item->formatDate(); ?></i><br>
                                </div>
                            </div>
                        </li>
                        <div class="clearfix"></div>
                    <?php endforeach; ?>
                <?php endif; ?>
            </ul>
            <div class="clearfix"></div>
            <?php if (!$this->isStaff): ?>
                <textarea style="width: 97%" name="note_content" id="note_content" placeHolder="Write notes ..."></textarea>
                <div class ="controls" style="float: right">
                    <!--<br>-->
                    <a class="btn btn-success"  onclick="create_note()">
                        <i class="icon-plus"></i>&nbsp;Add Notes
                    </a>
                </div>
            <?php endif; ?>
            <div class="pagination pagination-centered">
                <?php
                $this->widget('application.widgets.MyLinkPager', array(
                    'pages'                => $pages,
                    'header'               => '',
                    'maxButtonCount'       => 5,
                    'nextPageLabel'        => '&raquo;',
                    'firstPageLabel'       => '←',
                    'lastPageLabel'        => '→',
                    'prevPageLabel'        => '&laquo;',
                    'selectedPageCssClass' => 'active',
                ))
                ?>
            </div>
        </div>
    </div>
</div>
<script>
    function create_note() {
        if ($("#note_content").val() == '') {
            alert('Don\'t be so empty');
            return false;
        }
        $.post('<?php echo Yii::app()->createUrl('Customer/CreateNote'); ?>', {
            note_content: $("#note_content").val(),
            cus_id: '<?php echo $model->id ?>'
        }, function(msg) {
            var html = '<li>';
            html += '<div class="row-fluid">';
            html += '<div class="span2">';
            html += '<a href="' + msg.author_link + '" title="' + msg.author_name + '">';
            html += '<img class="avatar" src="' + msg.author_img + '">';
            html += '</a>';
            html += '</div>';
            html += '<div class="span10">';
            html += '<a href="' + msg.author_link + '">';
            html += '<i><strong>' + msg.author_name + '</strong> noted:</i> </a>"' + msg.note;
            html += '"<br>';
            html += '<i>at ' + msg.date + '<br>';
            html += '</div></div>';
            html += '<div class="clearfix"></div>';
            html += '</li>';

            jQuery('.dashboard-list').prepend(html);
            jQuery('#note_content').val('');
        }, 'json');
    }
</script>